﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Configuration;
using PlanB.Core.Configuration;
using PlanB.ShareDove.ConferenceOrganization.BusinessLayer;
using PlanB.ShareDove.ConferenceOrganization.BusinessLayer.DataLayerInterface.Entities;
using System.ServiceModel.Activation;
using PlanB.ShareDove.ConferenceOrganization.ServiceLayer.ServiceFacade.Entities;

namespace PlanB.ShareDove.ConferenceOrganization.ServiceLayer.WcfService
{

    //TODO: remove the references to the data layer implementations when finished with the testing - they are here just to enable us debugging (stepping into those assemblies). In the reality, the dependencies to these assemblies are injected.

    /// <summary>
    /// Exposing Conference Organization Solution feature through an ASP.NET and SharePoint compatible WCF Service
    /// This service uses BasicHttpBinding, ASP.NET compatibility mode and NTLM security
    /// It is build with .NET 3.5 so that it can create SharePoint content
    /// </summary>
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
    public class WcfService : IWcfService
    {

        /// <summary>
        /// Dummy data 
        /// </summary>
        /// <returns></returns>
        public List<string> GetSomeData()
        {
            ServiceFacade.ServiceFacade facade = new ServiceFacade.ServiceFacade();
            return facade.GetSomeDummyData();
        }



        /// <summary>
        /// Get sessions fora specified day from the business layer
        /// </summary>
        /// <param name="day">The day for which we want to retrieve the sessions</param>
        /// <returns>List of the lightweight seriazable session objects, suitable for transporting through the data service</returns>
        public List<ConferenceSessionLite> GetAgendaForDay(DateTime day)
        {
            ServiceFacade.ServiceFacade facade = new ServiceFacade.ServiceFacade();
            return facade.GetAgendaForDay(day);

        }


        /// <summary>
        /// Gets a list of the session names which take part on a specified day
        /// </summary>
        /// <param name="day"></param>
        /// <returns></returns>
        public List<string> GetSessionNamesForDay(DateTime day)
        {
            try
            {
                List<ConferenceSessionLite> sessions = GetAgendaForDay(day);
                List<string> names = new List<string>();
                foreach (ConferenceSessionLite session in sessions)
                {
                    names.Add(session.Title);
                }
                return names;
            }
            catch (Exception ex)
            {
                throw new FaultException(
                new FaultReason(ex.Message),
                new FaultCode("Error retrieving session names for day")
                );
            }
        }
    }
}
